package com.dhecp.project.system.service.impl;

import java.util.List;
import java.util.Map;

import com.dhecp.common.core.domain.AjaxResult;
import com.dhecp.core.constant.DataFiltering;
import com.dhecp.core.utils.PageUtils;
import com.dhecp.framework.util.ShiroUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dhecp.project.system.domain.SysUserBook;
import com.dhecp.project.system.mapper.SysUserBookMapper;
import com.dhecp.project.system.service.SysDictionaryForFieldService;
import com.dhecp.project.system.service.SysUserBookService;

/**
 * 员工通讯录 服务层
 * @author DH-Xxj
 * @version 2019年10月18日
 */
@Service
public class SysUserBookServiceImpl implements SysUserBookService {

    private static final Logger log = LoggerFactory.getLogger(SysUserBookServiceImpl.class);
    
    @Autowired
    private SysUserBookMapper userBookMapper;

    @Autowired
    private SysDictionaryForFieldService dictionaryForFieldService;

	/**
	 * 根据条件查询员工通讯录
	 * @param params
	 * @return List-SysUserBook
	 * @throws Exception
	 * @author DH-Xxj
	 */
    @Override
    public List<SysUserBook> queryUserBookList(Map<String, Object> params) throws Exception {
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
        params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));		//常规查询条件SQL语句
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));		//数据权限查询条件SQL语句
        params.put("mandator", ShiroUtils.getMandatorId());
        
  		if (params.get("field") == null || params.get("field") == ""){
  			String orderBy = "userId asc";
  			PageUtils.startPageOrder(orderBy);
  		}else{
  			PageUtils.startPage();	
  		}
        return userBookMapper.findUserBookList(params);
    }

	/**
     * 修改备注信息
     * @param userId 必要参数：用户编号
     * @param vBzXx 必要参数：备注信息
	 * @return
	 * @author DH-Xxj
	 */
    @Override
    public AjaxResult updateBzXx(Map<String, Object> params) {
    	if (params.get("userId") == null || params.get("userId") == ""){
    		params.put("userId", "userId");
    	}if (params.get("vBzXx") == null || params.get("vBzXx") == ""){
    		params.put("vBzXx", "");
    	}
    	userBookMapper.updateBzXx(params);
        return AjaxResult.success("操作成功");
    }
    
}
